package com.dom.invoapp.modular.provider;

import com.dom.api.basic.BasicStorApi;
import com.dom.common.model.vo.basic.B099A;
import com.dom.common.model.vo.basic.B099R;
import com.dom.common.model.vo.basic.StorInfo;
import com.dom.invoapp.dao.entity.TStorInfo;
import com.dom.invoapp.dao.service.ITStorInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description 基础数据服务-仓库信息
 * @Author xllei
 * @Date 2018/11/14 下午2:03
 * @Version 1.0
 **/
@Slf4j
@RestController
public class BasicStorProvider extends AbstractProvider implements BasicStorApi {
    @Autowired
    private ITStorInfoService storInfoService;

    @Override
    public B099A getStorList(B099R request) {
        List<TStorInfo> records = storInfoService.selectInfoList(0);

        List<StorInfo> storInfos = new ArrayList<>();
        records.forEach(entity->{
            StorInfo info = buildPropertites(entity);
            storInfos.add(info);
        });

        B099A response = new B099A();
        response.setStorInfoData(storInfos);
        response.setTotalNum(storInfos.size());
        return response;
    }

    private StorInfo buildPropertites(TStorInfo entity){
        StorInfo storInfo = new StorInfo();
        BeanUtils.copyProperties(entity, storInfo);
        return storInfo;
    }
}
